﻿
namespace Apache.Cassandra.Client {
    using System;
    using System.Linq;
    using Apache.Cassandra;

    [CLSCompliant(false)]
    public static class SuperColumnExtensions {

        public static Column GetItem(this SuperColumn supercolumn, int i) {
            if (supercolumn == null) {
                return null;
            }

            return supercolumn.Columns[i];
        }

        public static Column GetItem(this SuperColumn supercolumn, byte[] name) {
            if (supercolumn == null) {
                return null;
            }
            if (name == null) {
                throw new ArgumentNullException("name");
            }

            foreach (Column i in supercolumn.Columns) {
                if (name.SequenceEqual(i.Name)) {
                    return i;
                }
            }

            return null;
        }

        public static byte[] GetValue(this SuperColumn supercolumn, int i) {
            if (supercolumn == null) {
                return null;
            }

            Column column = supercolumn.GetItem(i);
            return null != column ? column.Value : null;
        }

        public static byte[] GetValue(this SuperColumn supercolumn, byte[] name) {
            if (supercolumn == null) {
                return null;
            }
            if (name == null) {
                throw new ArgumentNullException("name");
            }

            Column column = supercolumn.GetItem(name);
            return null != column ? column.Value : null;
        }
    }
}
